package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class Person here.
 * 
 * @author (Frederik, Simon, Claus, Minh, Nichlas & Nicolai) 
 * @version (a version number or a date)
 */
public class Person
{
    // instance variables - replace the example below with your own
    private ArrayList<Loan> loans;
    private String name;
    private String address;
    private String postalCode;
    private String city;
    private String phone;

    /**
     * Constructor for objects of class Person
     */
    public Person(String name, String address, String postalCode, String city, String phone)
    {
        // initialise instance variables
        loans =new ArrayList<Loan>();
        this.name = name;
        this.address = address;
        this.postalCode = postalCode;
        this.city = city;
        this.phone = phone;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getName()
    {
        return name;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getAddress()
    {
        return address;
    }

    public void setPostalCode(String postalCode)
    {
        this.postalCode = postalCode;
    }

    public String getPostalCode()
    {
        return postalCode;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCity()
    {
        return city;
    }

    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public String getPhone()
    {
        return phone;
    }

    public void addLoan(Loan l)
    {
        l.getCopy().setIsHome(false);
        loans.add(l);
    }

    public void deleteLoan(Loan l)
    {
        loans.remove(l);
    }

    /**
     * En metode til at finde en person
     * Vi starter med vores if statement som lyder
     * (hvis ikke fundet og i strørrelse er større end loans) 
     * gør vi
     * (hvis serialNumber er lig med (lånet <-> kopien <-> serieNummeret)
     * ellers incrementere vi med en
     * og søger igen
     * hvis fundet retuneres lånet
     * 
     * @return det søgte lån
     */
    public Loan findLoan(String id)
    {
        int i = 0;
        boolean found = false;
        while (!found && i<loans.size()){

            if (id.equals (loans.get(i).getId())){
                found = true;
            }
            else {
                i++;
            }

            if (found){                
                return loans.get(i);
            }

        }
        return null;   
    }

    /**
     * Prints information about persons state. 
     */
    public void printInfo()
    {
        System.out.println("***Person***");
        System.out.println("Name: " + name);
        System.out.println("Phone: " + phone);
        System.out.println("Address: " + address);
        System.out.println("City: " + city);
        System.out.println("Postal code: " + postalCode);
        System.out.println("Number of loans: " + getLoansSize());
        System.out.println("");
    }
    
    public int getLoansSize()
    {
        return loans.size();
    }

}
